﻿using System;
using System.Collections.Generic;
using System.Text;
using OpenWings.Entities;
using System.Diagnostics;
using System.Drawing;

namespace OpenWings.UI.Elements
{
    public class ListViewItemServer : ListViewItem<Server>
    {
        public ListViewItemServer(Server server)
            : base(server)
        {
            this.SubItems.AddRange(new string[] { "", "", "" });
            PopulateItem();

            this.InnerEntity.DirtyChanged += new EventHandler<DirtyChangedEventArgs>(InnerEntity_DirtyChanged);
        }

        void InnerEntity_DirtyChanged(object sender, DirtyChangedEventArgs e)
        {
            PopulateItem();
        }

        void PopulateItem()
        {
            this.Text = InnerEntity.Name;
            this.SubItems[1].Text = InnerEntity.LoginURI;
            this.SubItems[2].Text = InnerEntity.Notes;
            this.SubItems[3].Text = InnerEntity.Type.ToString();

            if (InnerEntity.IsDirty)
                this.Font = new Font(new FontFamily("Trebuchet MS"), 10, FontStyle.Bold);
            else
                this.Font = new Font(new FontFamily("Trebuchet MS"), 10, FontStyle.Regular);
        }
    }
}
